$(function() {
	$("#my_info #uHead").attr("src", $.cookie("uHeadurl"))
	$("#my_info #username input").attr("placeholder", $.cookie("uName"))
	$("#my_info #username span:first").html($.cookie("uName"))
	show_username_input()
	change_username()
})

function show_username_input() {
	$("#change_username").click(function() {
		$("#username_span").addClass("d-none")
		$("#username_input").removeClass("d-none")
		event.stopPropagation()
	})
}

function change_username() {
	input = $("#username_input input")
	input.blur(function() {
		if (input.val().length > 0) {
			$.post("http://193.112.72.237/Web-comfun/web/index.php?r=user/changename", {
				"session": $.cookie("session"),
				"name": input.val()
			}, function(data) {
				if (data['code'] == 501) {
					console.log(data)
					$.cookie("uName", input.val(), {
						path: "/",
						expires: 7
					})
				}else{
					
				}
				window.location.reload()
			})
		}
	})
}
